package org.shana.shortlink.admin.controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import lombok.RequiredArgsConstructor;
import org.shana.shortlink.admin.remote.LinkGotoRemoteService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
public class LinkGotoController {

    private final LinkGotoRemoteService shortLinkService=new LinkGotoRemoteService() {
    };

    @GetMapping("/{short_url}")
    public void gotoLink(@PathVariable("short_url") String url,ServletRequest request,ServletResponse response) throws ServletException, IOException {
        shortLinkService.restoreUrl(url, request, response);
    }
}
